package com.itheima.controller;

import com.itheima.service.UserService;
import com.itheima.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/user")
@RefreshScope //热更新 刷新这个实体
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${myconfig.welcome}")
    private String welcome;

    @Autowired
    private Environment environment;



    /***
     * 根据id查询用户详情
     */
    @GetMapping(value = "/{id}")
    public User one(@PathVariable(value = "id") Long id) {
        return userService.findById(id);
    }

    @GetMapping("welcome")
    public String now() {
        System.out.println("welcome:" + welcome);
        System.out.println("environment:" + environment.getProperty("myconfig.welcome"));
        return "------" + welcome + "--------";
    }
}
